package com.example.hesperidesbot;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class OpcionesActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_opciones);

		Intent intent = getIntent();
		EditText apiKeyText = (EditText) findViewById(R.id.apiKey);
		EditText feedIDText = (EditText) findViewById(R.id.feedID);
		EditText intervaloText = (EditText) findViewById(R.id.intervalo);
   
		SharedPreferences prefs = getSharedPreferences("strings", Context.MODE_PRIVATE);    
		apiKeyText.setText(prefs.getString("apiKey", "BOlAZBIIPtjWwRwzlX8DiRyVuQWSAKxnZlpTbEFIZXRsdz0g"));
		feedIDText.setText(prefs.getString("feedID", "118413"));
		intervaloText.setText(prefs.getString("intervalo", "30000"));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.opciones, menu);
		return true;
	}

	public void confirmar(View view) {

		EditText apiKeyText = (EditText) findViewById(R.id.apiKey);
		EditText feedIDText = (EditText) findViewById(R.id.feedID);
		EditText intervaloText = (EditText) findViewById(R.id.intervalo);

		SharedPreferences prefs = getSharedPreferences("strings", Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = prefs.edit();
		editor.putString("apiKey", apiKeyText.getText().toString());
		editor.putString("feedID", feedIDText.getText().toString());
		editor.putString("intervalo", intervaloText.getText().toString());
		editor.commit();

		Intent intent = new Intent(this, MainActivity.class);
		startActivity(intent);	
	}

	public void cancelar(View view) {
		Intent intent = new Intent(this, MainActivity.class);
		startActivity(intent);	
	}    

}
